gpNamespace.gpMiddleLayer = cc.Layer.extend({
	rankList: null,
	friendsList: null,
	content1Field:null,
	rankListTouchable: false,
	eggAvi: null,
	scrollNews:null,
	listTopBg2:null,
	ctor: function(){
		this._super();
		this.init();
	},

	init:function(){

		var size = cc.winSize;
		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.jdcBtAnimationRes.Jdc_png,
				gpNamespace.jdcBtAnimationRes.Jdc_plist,
				gpNamespace.jdcBtAnimationRes.Jdc_json);
		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.dhqBtAnimationRes.Dhq_png,
				gpNamespace.dhqBtAnimationRes.Dhq_plist,
				gpNamespace.dhqBtAnimationRes.Dhq_json);
		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.startBtAnimationRes.start_png,
				gpNamespace.startBtAnimationRes.start_plist,
				gpNamespace.startBtAnimationRes.start_json);
//		ccs.armatureDataManager.addArmatureFileInfo(
//				gpNamespace.xsBtAnimationRes.Xs_png,
//				gpNamespace.xsBtAnimationRes.Xs_plist,
//				gpNamespace.xsBtAnimationRes.Xs_json);
		
		//新闻背景
		var newsBg = new cc.MenuItemImage(gpNamespace.mainSenceFirst.TopLayerMessageBackground,gpNamespace.mainSenceFirst.TopLayerMessageBackground,this.openSjpdCallback,this);
		newsBg.attr({
			x: size.width/2,
			y: size.height-115,
			anchorX: 0.5,
			anchorY: 0.5
		});
		var newsMenu = new cc.Menu(newsBg);
		newsMenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		this.addChild(newsMenu);
		//新闻喇叭
		var newsHorn = new cc.Sprite(gpNamespace.mainSenceFirst.TopLayerMessageLaBa);
		newsHorn.attr({
			x: size.width/2-350,
			y: newsBg.getPositionY()
		});
		this.addChild(newsHorn);

		var scrollNews = new cc.LabelTTF("",gpNamespace.DEFAULTFONT,22);
//		scrollNews.setFontFillColor(cc.color.WHITE);
		scrollNews.setFontFillColor(cc.color(6, 255, 128, 255))	;
		scrollNews.attr({
			x: 70,
			y: 3,
			anchorX: 0,
			anchorY: 0
		});
		this.scrollNews = scrollNews;
		newsBg.addChild(scrollNews);
		this.setNewsScroll();

		//左侧背景
		var listBg = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListBackground);
		listBg.attr({
			x: 380,
			y: size.height/2-30
		});
		this.addChild(listBg);
		//排行顶部一个背景
		var listTopBg2 = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListTopBackground);
		listTopBg2.attr({
			x: 145+listTopBg2._getWidth(),
			y: 530,
			anchorX: 0,
			anchorY: 0
		});
		this.listTopBg2=listTopBg2;
		this.addChild(listTopBg2,2);
		
		//财富排行
		var page1On = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListRichTopSelected);
		var page1Off = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListRichTopNormal);
		var page1 = new cc.MenuItemToggle(page1Off, page1On, this.page1CallbackFunction, this);
		page1.attr({
			x:0,
			y:0
		})
		this.page1=page1;
		page1.setUserData(this);
		//聊天室
		var page2On = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListMessageTopSelected);
		var page2Off = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListMessageTopNormal);
		var page2 = new cc.MenuItemToggle(page2Off, page2On, this.page2CallbackFunction, this);
		page2.attr({
			x:250,
			y:0
		})
		page2.setSelectedIndex(1);
		this.page2=page2;
		page2.setUserData(this);
		
		var TopListMenu = new cc.Menu(page1,page2);
		TopListMenu.attr({
			x:255,
			y:555,
		})
		this.addChild(TopListMenu,3);

		var talkSelectHelp =new cc.MenuItemSprite(new cc.Sprite(), new cc.Sprite(),this.page1CallbackFunction,this);
		talkSelectHelp.setContentSize(240, 45);
		talkSelectHelp.setUserData(this);
		talkSelectHelp.attr({
			x:255,
			y:555,
		});
		var rankSelectHelp =new cc.MenuItemSprite(new cc.Sprite(), new cc.Sprite(),this.page2CallbackFunction,this);
		rankSelectHelp.setContentSize(240, 45);
		rankSelectHelp.setUserData(this);
		rankSelectHelp.attr({
			x:505,
			y:555,
		});

		//左侧排行菜单顶部俩off文字辅助菜单，扩大选区
		var leftTopMenuHelp = new cc.Menu(talkSelectHelp,rankSelectHelp);
		leftTopMenuHelp.x = 0;
		leftTopMenuHelp.y = 0;
		leftTopMenuHelp.anchorX = 0;
		leftTopMenuHelp.anchorY = 0;
		this.addChild(leftTopMenuHelp,5);

		//自己的排行信息
/*		var MyselfyelloBg = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListMyItemBackground);
		MyselfyelloBg.attr({
			x:140,
			y:420,
			anchorX:0,
			anchorY:0
		})
		this.addChild(MyselfyelloBg);*/
		
		if(historyTalkInfo != null){
			xinyou.netManager.getHistoryTalk();
		}else{
			this.scheduleOnce(function(){
				if(historyTalkInfo != null){
					this.setFriendsContainer(historyTalkInfo);
				}
			},0.5);
		}

		//财富排行列表
		var rankList = new tableViewPro.TableView(this, cc.size(510, 300), 0);
		rankList.setPosition(123, 118);
		rankList.setAnchorPoint(0, 0);
		this.rankList = rankList;
		this.addChild(this.rankList);
		this.rankList.setTouchEnabled(false);
		this.rankList.setBarOffset(0, 0);  
		
		cc.log("gpNamespace.systemMessageLength>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+gpNamespace.systemMessageLength);
		//好友列表
		var friendsList;
		if(gpNamespace.systemMessageLength==1){
			friendsList = new tableViewPro.TableView(this,cc.size(450,300),0);
		}else{
			friendsList = new tableViewPro.TableView(this,cc.size(450,270),0);
		}
		friendsList.setPosition(145,195);
		friendsList.setAnchorPoint(0, 0);
		this.friendsList = friendsList;
		this.addChild(this.friendsList);
		this.friendsList.setTouchEnabled(false);
		this.friendsList.setBarOffset(0, 0);
		
		

		//右侧立即开始、兑换券、新手教程
		var startBt = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerStartButton, gpNamespace.mainSenceFirst.MiddleLayerStartButton, this.startBtFunction, this);
		var startAvi = new ccs.Armature("pdk_zjm_an_lijikaishi_dh");
		startAvi.getAnimation().playWithIndex(0);
		startAvi.getAnimation().setSpeedScale(1);
		startAvi.setScale(1.0);
		startAvi.setAnchorPoint(0, 0);
		startAvi.setPosition(0, 6);
		startBt.addChild(startAvi,3);
		startAvi.getAnimation().setMovementEventCallFunc(this.freeCallBackRemove, this);
		
		var jdcBt = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerClassicsButton, gpNamespace.mainSenceFirst.MiddleLayerClassicsButton, this.jdcBtFunction, this);
		var jdcBtAvi = new ccs.Armature("pdk_zjm_an_jingdianchang_dh");
		jdcBtAvi.getAnimation().playWithIndex(0);
		jdcBtAvi.getAnimation().setSpeedScale(1);
		jdcBtAvi.setScale(1);
		jdcBtAvi.setAnchorPoint(0, 0);
		jdcBtAvi.setPosition(0, 9);
		jdcBt.addChild(jdcBtAvi,3);
		jdcBtAvi.getAnimation().setMovementEventCallFunc(this.freeCallBackRemove, this);

		var dhqBt = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerExchangeTicketButton, gpNamespace.mainSenceFirst.MiddleLayerExchangeTicketButton, this.dhqBtFunction, this);
		var dhqBtAvi = new ccs.Armature("pdk_zjm_an_duihuanquanchaokuaisai_dh");
		dhqBtAvi.getAnimation().playWithIndex(0);
		dhqBtAvi.getAnimation().setSpeedScale(1);
		dhqBtAvi.setScale(1);
		dhqBtAvi.setAnchorPoint(0, 0);
		dhqBtAvi.setPosition(0, 6);
		dhqBt.addChild(dhqBtAvi,3);
		dhqBtAvi.getAnimation().setMovementEventCallFunc(this.freeCallBackRemove, this);

/*		var xsBt = new cc.MenuItemImage(gpNamespace.plaza.Plaza_XsBt, gpNamespace.plaza.Plaza_XsBt, this.xsBtFunction, this);
		var xsBtAvi = new ccs.Armature("pdk_zjm_an_duihuanquanchaokuaisai_dh");
		xsBtAvi.getAnimation().playWithIndex(0);
		xsBtAvi.getAnimation().setSpeedScale(1);
		xsBtAvi.setScale(1);
		xsBtAvi.setAnchorPoint(0, 0);
		xsBtAvi.setPosition(0, 0);
		xsBt.addChild(xsBtAvi,3);
		xsBtAvi.getAnimation().setMovementEventCallFunc(this.freeCallBackRemove, this);*/
		var rightMenu = new cc.Menu(startBt,jdcBt, dhqBt);
		rightMenu.attr({
			x: 950,
			y: 348
		});
		rightMenu.alignItemsVerticallyWithPadding(-10);
		this.addChild(rightMenu);

		this.schedule(function(){
			this.animationSchedule(2,[startAvi,jdcBtAvi,dhqBtAvi]);
		}, 8);

		gpNamespace.TyNetManager.getInstance().setgpMiddleLayer(this);//将本页面信息传给netManager
		if(rankInfo != null){
			xinyou.netManager.getRank(1);//获取排行榜
		}else{
			this.scheduleOnce(function(){
				if(rankInfo != null){
					this.setRankContainer(rankInfo);
				}
			},0.5);
		}
//		setInterval("xinyou.netManager.getHistoryTalk()",1000);
		if(historyTalkInfo != null){
			this.scheduleOnce(function(){
				xinyou.netManager.getHistoryTalk();
			},0.5);
//			this.setFriendsContainer(gpNamespace.TySocialTemp);
			cc.log("gpNamespace.TySocialTemp.length>>>>>>>>>>>>>>>>"+gpNamespace.TySocialTemp.length);
			cc.log("historyTalkInfo>>>>>>>>>>>>>>>>>>>ok2"+historyTalkInfo.itemCount);
		}
	},

	animationSchedule:function(delay,sender) {    
		this.scheduleOnce(function(){sender[0].getAnimation().playWithIndex(0);},2);
		this.scheduleOnce(function(){sender[1].getAnimation().playWithIndex(0);},4);
		this.scheduleOnce(function(){sender[2].getAnimation().playWithIndex(0);},6);
	},

	openSjpdCallback:function(sender){
		cc.log("世界频道显示");
//		cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.CddMainScene()));
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		tyNamespace.setMenuEnable(sender);
		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer();
		modelLayer.setTouchArea(cc.size(875, 568), cc.p(202, 70));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 4);

		var sjpdLayer = new gpNamespace.SjpdLayer();
		sjpdLayer.attr({
			x: 0,
			y: cc.winSize.height
		});
		modelLayer.addChild(sjpdLayer);
		tyNamespace.AnimationManager.nodeJumpShow(sjpdLayer, -cc.winSize.height);
	},
	
	checkEntrence: function (limitGold) {
		var currentGold = userInfo.gold;
		var pochanCount = gpNamespace.LoginInfo.POCHANCOUNT;

		if (parseInt(currentGold) < 100 && parseInt(pochanCount) < 3) {
			tyNamespace.IsPochan = true;
			gpNamespace.GameConfig.SCENETYPE = 0;
			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
			return false;
		}

		var oneRMB = gpNamespace.LoginInfo.ISBUYONE;

		cc.log("pochanCount:" + pochanCount);

		if (parseInt(currentGold) < 100 && parseInt(pochanCount) >= 3 && !oneRMB) {
			tyNamespace.IsBuyOne = true;
			gpNamespace.GameConfig.SCENETYPE = 0;
			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
			return false;
		}

		if (!tyNamespace.IsPochan && !gpNamespace.IsBuyOne && parseInt(currentGold) < parseInt(limitGold)) {
			tyNamespace.IsLimit = true;
			gpNamespace.GameConfig.SCENETYPE = 0;
			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
			return false;
		}

		return true;
	},
	
	startBtFunction:function(sender){
		var self = this;
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		tyNamespace.addWaitLayer();

		sender.runAction(cc.sequence(cc.scaleTo(0.1, 1.02, 0.98), cc.scaleTo(0.1, 0.98, 1.02), cc.scaleTo(0.1, 1, 1), cc.callFunc(function () {
			if (!self.checkEntrence(300)) {
				return;
			}

			//TODO 待优化
			gpNamespace.NetManager.getInstance();

			//inRoom (0:麻将，1:斗地主，2:德州,5:跑的快) (1,2,3,4,5,6 房间等级 -1 自动匹配) (0:不自动坐下，1:自动坐下 (包厢为0，其他情况都是1)))
			xinyou.netManager.inRoom(6, -1, 1);
		}, this)));
	},

	jdcBtFunction: function (sender) {
		cc.log("经典场显示");
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		sender.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
		tyNamespace.setMenuEnable(sender);
		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer();
		modelLayer.setTouchArea(cc.size(1138, 576), cc.p(72, 70));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 4);

		var jdcLayer = new gpNamespace.JdcLayer();
		jdcLayer.attr({
			x: 0,
			y: cc.winSize.height
		});
		modelLayer.addChild(jdcLayer);
		tyNamespace.AnimationManager.nodeJumpShow(jdcLayer, -cc.winSize.height);
	},

	dhqBtFunction: function (sender) {
		cc.log("兑换券赛显示");
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		sender.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
		tyNamespace.setMenuEnable(sender);
		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer(70);
		modelLayer.setTouchArea(cc.size(1138, 590), cc.p(72, 72));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 4);
		var dhqLayer = new gpNamespace.DhqLayer();
		dhqLayer.attr({
			x: 0,
			y: cc.winSize.height,
		});
		modelLayer.addChild(dhqLayer);
		tyNamespace.AnimationManager.nodeJumpShow(dhqLayer, -cc.winSize.height);
	},
 
	//设置好友列表数据
	setFriendsContainer:function(array){
		cc.log("设置好友列表数据>>>>");
		if(gpNamespace.systemMessageLength==1){
			cc.log("gpNamespace.systemMessageLength==1");
			this.friendsList.setsize(cc.size(450, 300));
		}else{
			cc.log("gpNamespace.systemMessageLength==2");
			this.friendsList.setsize(cc.size(450, 270));
		}
		tyNamespace.SlicedString = []
		for(var i = 0;i<array.length;i++){
			cc.log("array[i].length"+array[i].length);
			var slicedString = tyNamespace.GetSlicedString(array[i],40);
		}
		cc.log(array.length+"++++++++++++++++"+tyNamespace.SlicedString.length);
		
		this.friendsList.clearData();
		this.friendsList.addData({
			"barInfo": {"width": 2, "height": 0},
			"sameItem": [
			             {
			            	 "dataType": 1,
			            	 "headInfo": {
			            		 "headType": 0,
			            		 "offset": 0,
			            		 "imageName": "",
			            		 "width": 0
			            	 },
			            	 "pageInfo": {"colCount": 1},
			            	 "cellInfo": {
			            		 "cellType": 0,
			            		 "cellCount": tyNamespace.SlicedString.length,
			            		 "imageName": "",
			            		 "height": 30
			            	 }
			             }
			             ]
		})
		this.friendsList.showData();
		this.friendsList.visible=true;
		this.friendsList.setTouchEnabled(true);
		var cellCount = this.friendsList.currentItem.cellInfo.cellCount;
		var cellType = this.friendsList.currentItem.cellInfo.cellType;
		var currentPage = this.friendsList.currentPage;
		
		for (var a = 0; a < cellCount; a++) {
			var cell;
			switch (cellType) {
			case 0://sprite
				cell = currentPage.getChildByTag(a);
				break;
				/*case 1://menu
    			cell = currentPage.getChildByName(xzgbNamespace.TVMENU).getChildByTag(a);
    			break;*/
			}
			newStr = tyNamespace.SlicedString[a];
			newStr = this.cTrim(newStr, 1);
			cc.log("array"+newStr);
			this.setFriendCell(a, cell, newStr);
		}
		this.friendsList.setScrollPosition(tyNamespace.SlicedString.length);
		this.setMessageSeng();
	},
	
	setMessageSeng:function(){
		//文本框背景
		var labelBackground = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemEditText);
		labelBackground.attr({
			x: 5,
			y: -65,
			anchorX: 0,
			anchorY: 0
		});
		this.friendsList.addChild(labelBackground);
		//内容输入框
		var content1FieldSize = cc.size(290, 40);
		var content1FieldScale9Sprite = new cc.Scale9Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemEditText);
		var content1Field = new cc.EditBox(content1FieldSize, content1FieldScale9Sprite);
		content1Field.setPlaceHolder("最多能发30字哦！");
		content1Field.setMaxLength(30);
		content1Field.setPlaceholderFontColor(cc.color(255,255,255, 255));
		content1Field.setFontColor(cc.color(255, 255, 255));
		content1Field.setPlaceholderFontSize(18);
		content1Field.setFontSize(18);
		content1Field.setInputMode(cc.EDITBOX_INPUT_MODE_SINGLELINE);
		content1Field.setInputFlag(cc.EDITBOX_INPUT_FLAG_SENSITIVE);
		content1Field.setReturnType(cc.KEYBOARD_RETURNTYPE_DONE);
		content1Field.setDelegate(this);
		content1Field.attr({
			x: 20,
			y: -60,
			anchorX: 0,
			anchorY: 0
		});
		this.friendsList.addChild(content1Field);
		this.content1Field = content1Field;
		
		
		//发送
		var send = new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListItemSendMessageButton, gpNamespace.mainSenceFirst.MiddleLayerListItemSendMessageButton, this.sendCallbackFunction, this);
		send.attr({
			x: 130,
			y: 50
		});
		send.setScale(0.8);
		var menu = new cc.Menu(send);
		menu.attr({
			x:260,
			y: -90,
			anchorX: 0,
			anchorY: 0
		});
		this.friendsList.addChild(menu);
	},
	setFriendCell:function(index,cell,arry){
		cc.log("index+arry"+index+"  "+arry);
		cc.log(">>>>>>>>>>>>"+gpNamespace.pdkcharType[index]);
		var str = new cc.LabelTTF(arry,gpNamespace.DEFAULTFONT,20);
		if(gpNamespace.pdkcharType[index] == 3){
			str.setFontFillColor(cc.color(253, 212, 98));
		}
		if(gpNamespace.pdkcharType[index] == 1){
			str.setFontFillColor(cc.color(88, 255, 94));
		}
		str.attr({
			x:5,
			y:5,
			anchorX:0,
			anchorY:0
		})
		cell.addChild(str);
	},

	setFirstLineContainer:function(firstStr){
		this.friendsList.getChildByTag(111) && this.friendsList.getChildByTag(111).removeFromParent();
		this.friendsList.getChildByTag(112) && this.friendsList.getChildByTag(112).removeFromParent();
		tyNamespace.SlicedString = [];
		tyNamespace.GetSlicedString(firstStr,40);
		firstStr = tyNamespace.SlicedString[0];
		var str = new cc.LabelTTF(firstStr,gpNamespace.DEFAULTFONT,20);
		str.attr({
			x:0,
			y:307,
			anchorX:0,
			anchorY:0
		});
		str.setTag(111);
		str.setFontFillColor(cc.color(253, 212, 98));
		this.friendsList.addChild(str);
		if(gpNamespace.systemMessageLength==2){
			var secondStr = tyNamespace.SlicedString[1];
			var label2 = new cc.LabelTTF(secondStr,gpNamespace.DEFAULTFONT,20);
			label2.attr({
				x:0,
				y:277,
				anchorX:0,
				anchorY:0,
			})
			label2.setFontFillColor(cc.color(253, 212, 98));
			label2.setTag(112);
			this.friendsList.addChild(label2);
		}
	},
	//设置排行榜数据
	setRankContainer:function (array) {
		this.rankList.clearData();
		this.rankList.addData({
			"barInfo": {"width": 2, "height": 80},
			"sameItem": [
			             {
			            	 "dataType": 1,
			            	 "headInfo": {
			            		 "headType": 0,
			            		 "offset": 0,
			            		 "imageName": "",
			            		 "width": 0
			            	 },
			            	 "pageInfo": {"colCount": 1},
			            	 "cellInfo": {
			            		 "cellType": 0,
			            		 "cellCount": array.length-1,
			            		 "imageName": gpNamespace.mainSenceFirst.MiddleLayerListNormalItemBackground,
			            		 "height": 100
			            	 }
			             }
			             ]
		});
		currentNetManager = gpNamespace.NetManager.getInstance();
		if(currentNetManager.isReconnnect == false){
			this.rankList.showData();
		}
		this.rankList.visible=false;
		this.rankList.setTouchEnabled(false);
		var cellCount = this.rankList.currentItem.cellInfo.cellCount;
		var cellType = this.rankList.currentItem.cellInfo.cellType;
		var currentPage = this.rankList.currentPage;
//		cc.log("*******"+cellCount+">>"+cellType);
		for (var a = 0; a < cellCount; a++) {
			var cell;
			switch (cellType) {
			case 0://sprite
				cell = currentPage.getChildByTag(a);
				break;
				/*case 1://menu
    			cell = currentPage.getChildByName(xzgbNamespace.TVMENU).getChildByTag(a);
    			break;*/
			}
			this.setRankCell(a+1, cell, array);
		}
		tyNamespace.addWaitLayer();
		this.scheduleOnce(function(){
			for (var a = 0; a < cellCount; a++) {
				var cell = this.rankList.currentPage.getChildByTag(a);
				this.setUserHead(array[a+1][6], cell);
			}
			tyNamespace.removeWaitLayer();
		},0.2);
		this.setMyOwnRank(array[0]);
		
	},
	setMyOwnRank:function(myInfo){
		var yellowBg = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListMyItemBackground);
		yellowBg.attr({
			x: 20,
			y: 300,
			anchorX:0,
			anchorY:0
		});
		this.rankList.addChild(yellowBg,0);

		var rankIndex=new tyNamespace.NumLayer(myInfo[4],18,25,"sz_cdd_js_");
		rankIndex.attr({
			x: 70,
			y: 55
		});
		yellowBg.addChild(rankIndex,2);

		//头像背景
		var icon = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemUserBg);
		icon.attr({
			x: 115,
			y: 55,
			anchorX: 0,
			anchorY: 0.5
		});
		yellowBg.addChild(icon,2);
		qqImg = new cc.Sprite();
		qqImg.setScale(78 / qqImg.getContentSize().width, 78 / qqImg.getContentSize().height);
		qqImg.setAnchorPoint(0, 0);
		qqImg.setPosition(130, 16);
		yellowBg.addChild(qqImg);
		this.setUserHead(myInfo[6],yellowBg);

		var nameStrSub = null;
		//长度.substr(),返回一个从指定位置开始的指定长度的子字符串。
		if((nameStrSub = myInfo[7].toString()).length>8){
			nameStrSub = nameStrSub.substr(0,5)+"..." ;
		}
		//用户昵称
		var nikeName = new cc.LabelTTF(nameStrSub, gpNamespace.DEFAULTFONT, 20);
		nikeName.setFontFillColor(cc.color(108, 28, 11, 255));
		nikeName.attr({
			x: 340,
			y: 78,
			anchorX: 0.5,
			anchorY: 0.5
		});
		yellowBg.addChild(nikeName);

		//金币数
		var gold = new cc.LabelTTF(myInfo[2], gpNamespace.DEFAULTFONT, 20);
		gold.setFontFillColor(cc.color(108, 28, 11, 255));
		gold.attr({
			x: 340,
			y: 40,
			anchorX: 0.5,
			anchorY: 0.5
		});
		yellowBg.addChild(gold);
	},
	setRankCell: function (index, cell, array) {
//		var exchangeItems = [];
		var nameStrSub = null;
		//长度.substr(),返回一个从指定位置开始的指定长度的子字符串。
		if((nameStrSub = array[index][7].toString()).length>8){
			nameStrSub = nameStrSub.substr(0,5)+"..." ;
		}

		//排名

		if(index==1){
			var first = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemCrownFirst);
			first.attr({
				x: 70,
				y: 58
			});
			cell.addChild(first,3);
		}else if(index==2){
			var first = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemCrownSecond);
			first.attr({
				x: 70,
				y: 58
			});
			cell.addChild(first,3);
		}else if(index==3){
			var first = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemCrownThird);
			first.attr({
				x: 70,
				y: 58
			});
			cell.addChild(first,3);
		}else{
			var rankIndex=new tyNamespace.NumLayer(index,35,0,"sz_cdd_zjm_");
			rankIndex.attr({
				x: 70,
				y: 58
			});
			cell.addChild(rankIndex,2);
		}


		//头像背景
		var icon = new cc.Sprite(gpNamespace.mainSenceFirst.MiddleLayerListItemUserBg);
		icon.attr({
			x: 115,
			y: 55,
			anchorX: 0,
			anchorY: 0.5
		});
		cell.addChild(icon,2);
		qqImg = new cc.Sprite(gpNamespace.xinzeng.QQ);
		qqImg.setScale(78 / qqImg.getContentSize().width, 78 / qqImg.getContentSize().height);
		qqImg.setAnchorPoint(0, 0);
		qqImg.setPosition(130, 20);
		cell.addChild(qqImg);
		
		//用户昵称
		var nikeName = new cc.LabelTTF(nameStrSub, gpNamespace.DEFAULTFONT, 20);
		nikeName.setFontFillColor(cc.color(108, 28, 11, 255));
		nikeName.attr({
			x: 340,
			y: 78
		});
		cell.addChild(nikeName);

		//金币数
		var gold = new cc.LabelTTF(array[index][2], gpNamespace.DEFAULTFONT, 20);
		gold.setFontFillColor(cc.color(108, 28, 11, 255));
		gold.attr({
			x: 340,
			y: 40
		});
		cell.addChild(gold);
	},
	
	addUserHead: function (texture, cell) {
//		cc.log("########：："+cell);
		var imgSprite;
		if (texture) {
			imgSprite = new cc.Sprite(gpNamespace.xinzeng.QQ);
			imgSprite.initWithTexture(texture);

			imgSprite.setScale(78 / imgSprite.getContentSize().width, 78 / imgSprite.getContentSize().height);
			imgSprite.setAnchorPoint(0, 0);
			imgSprite.setPosition(130, 20);
//			imgSprite.setName("userHead");
			cell.addChild(imgSprite,1);
		}
	},

	setUserHead: function (headImgUrl,cell) {
//		var userHead = this.getChildByName("userHead");
//		userHead && userHead.removeFromParent(true);

		tyNamespace.loadImgByUrl(headImgUrl, this.addUserHead, this, cell);
	},
	
	setNewsScroll:function(){
		var i = 0;
		var self = this;
		this.schedule(function(){
			if(typeof lastThreeNews != "undefined"){
				if(lastThreeNews[i][2].length>32){
					lastThreeNews[i][2] = lastThreeNews[i][2].substring(0,28)+"...";
				}
//				cc.log("lastThreeNews[i][2].length:"+lastThreeNews[i][2].length);
				if(lastThreeNews[i][0] == 3){
					self.scrollNews.setFontFillColor(cc.color(255,205,79,255));
				}else{
					self.scrollNews.setFontFillColor(cc.color(77,255,143, 255));
				}
				this.scrollNews.setString(lastThreeNews[i][3]+":"+lastThreeNews[i][2]); 
				self.fadeInThenOut(this.scrollNews);
				i >= 2 ? i = 0 : i++;
			}
		},3.1);
	},
	fadeInThenOut: function(node){
		node.runAction(new cc.FadeTo(0.2,255));
		this.scheduleOnce(function(){
			node.runAction(new cc.FadeOut(0.2));
		},3);
	},
	
	page1CallbackFunction:function(sender){
//		tyNamespace.setMenuEnable(sender);
		var self = sender.getUserData();
		self.listTopBg2.x=140;
		self.page1.setSelectedIndex(1);
		self.page2.setSelectedIndex(0);
		self.rankList.visible=true;
		self.rankList.setTouchEnabled(true);
		self.friendsList.visible=false;
		self.friendsList.setTouchEnabled(false);
//		self.feedback.visible=true;
//		self.feedback.setTouchEnabled(true);
//		self.problem.visible=false;
//		self.problem.setTouchEnabled(false);
	},
	page2CallbackFunction:function(sender){
//		tyNamespace.setMenuEnable(sender);
		var self = sender.getUserData();
		self.listTopBg2.x=145 + self.listTopBg2.width;
		self.page1.setSelectedIndex(0);
		self.page2.setSelectedIndex(1);
		self.rankList.visible=false;
		self.rankList.setTouchEnabled(false);
		self.friendsList.visible=true;
		self.friendsList.setTouchEnabled(true);
//		self.feedback.visible=false;
//		self.feedback.setTouchEnabled(false);
//		self.problem.visible=true;
//		self.problem.setTouchEnabled(true);
	},
	
	sendCallbackFunction: function (sender) {
		cc.log("发送信息");

		tyNamespace.setMenuEnable(sender);
		
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		if(this.content1Field.getString()){
		xinyou.netManager.sendTalk(2, "", this.content1Field.getString());
		}else{
			tyNamespace.tipsJumper(1,"不能发送空消息！");
			return;
		}
	},
	
	// Description: sInputString 为输入字符串，iType为类型，分别为
	// 0 - 去除前后空格; 1 - 去前导空格; 2 - 去尾部空格
	cTrim:function (sInputString,iType){
		var sTmpStr = ' '
			var i = -1
			if(iType == 0 || iType == 1){
				while(sTmpStr == ' '){
					++i;
					sTmpStr = sInputString.substr(i,1)
				}
				sInputString = sInputString.substring(i)
			}
		if(iType == 0 || iType == 2) {
			sTmpStr = ' '
				i = sInputString.length
				while(sTmpStr == ' ') {
					--i
					sTmpStr = sInputString.substr(i,1)
				}
			sInputString = sInputString.substring(0,i+1)
		}
		return sInputString
	},
});